package com.sam.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by Administrator on 2016/6/6.
 */
public class FontTextView extends TextView {
    private Context context;
    private String fontpath;
    public FontTextView(Context context) {
        this(context,null);
    }

    public FontTextView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public FontTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;
        getAttrs(attrs);
        init();
    }

    private void getAttrs(AttributeSet attrs) {
        TypedArray ta=context.obtainStyledAttributes(attrs,R.styleable.FontTextView);
        fontpath=ta.getString(R.styleable.FontTextView_fontpathview);
        ta.recycle();
    }
    private void init() {
        try {
            if (fontpath!=null)setTypeface(Typeface.createFromAsset(context.getAssets(),fontpath));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
